//
//  LoveListenTableViewCellFirst.m
//  XYFMApp
//
//  Created by 岁变 on 16/8/31.
//  Copyright © 2016年 岁变. All rights reserved.
//

#import "LoveListenTableViewCellFirst.h"
#import "XYMacro.h"

@implementation LoveListenTableViewCellFirst

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        if ([user objectForKey:@"password"]) {
            _uid = [user objectForKey:@"target_id"];
        }

        _picImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_picImageView];
        
        _backImageVeiw = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_channel_item"]];
        [self.contentView addSubview:_backImageVeiw];
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor whiteColor];
        // _titleLabel.backgroundColor = [UIColor yellowColor];
        [self.contentView addSubview:_titleLabel];
        
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.textColor = [UIColor colorWithRed:0.44 green:0.44 blue:0.48 alpha:1.00];
        _contentLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_contentLabel];
        
        _playImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"catinfo_play_cnt"]];
        [self.contentView addSubview:_playImageView];
        
        _numberLabel = [[UILabel alloc] init];
        _numberLabel.text = _str;
        _numberLabel.textColor = [UIColor colorWithRed:0.44 green:0.44 blue:0.48 alpha:1.00];
        _numberLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_numberLabel];
        
        _fromLabel = [[UILabel alloc] init];
        _fromLabel.textColor =[UIColor colorWithRed:0.44 green:0.44 blue:0.48 alpha:1.00];
        _fromLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_fromLabel];
        
        _cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_cancelButton setImage:[UIImage imageNamed:@"cancel"] forState:UIControlStateNormal];
        [_cancelButton addTarget:self action:@selector(clickCancelButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_cancelButton];
    }
    return self;
}


- (void)clickCancelButton:(UIButton *)button {
    
    NSString *str1 = @"json=%7B%22session%22%3A%7B%22uid%22%3A%22";
    NSString *str2 = @"%22%2C%22sid%22%3A%22d7e3db20ebb641caa6fee8bab4e33f07%22%7D%2C%22operate%22%3A0%2C%22item_ids%22%3A%22";
    NSString *str3 = @"%22%7D";
    NSString *body = [[[[str1 stringByAppendingString:_uid] stringByAppendingString:str2] stringByAppendingString:[NSString stringWithFormat:@"%ld", _model.item_id]] stringByAppendingString:str3];
    
    [XYNetWorkParser POST:@"http://www.aiyinsitanfm.com/mobile/channel/procwatch.jhtml" andBody:body andBodyStyle:XYBodyString andHeader:URLHEADER andResponse:XYJSON andSuccessBlock:^(id result) {
    
        _dingyueModel = [PlayVCModelOfCollect modelWithDictionary:result];
        if (_dingyueModel.status.succeed == 1) {
            [_modelArr removeObjectAtIndex:_myIndexPath.row];
            BaseTableView *tableView = (BaseTableView *) self.nextResponder.nextResponder;
            [tableView reloadData];
        }

        
    } andFailureBlock:^(NSError *error) {}];
    
    
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    [_backImageVeiw mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(0);
        make.top.equalTo(self.contentView.mas_top).with.offset(10);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_backImageVeiw.mas_top).with.offset(5);
        make.left.equalTo(self.contentView.mas_left).with.offset(130);
        make.width.mas_offset(240);
        make.height.mas_offset(30);
    }];
    
    [_playImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(130);
        make.bottom.equalTo(_backImageVeiw.mas_bottom).with.offset(-10);
        make.height.mas_offset(10);
        make.width.mas_offset(10);
    }];
    
    
    [_numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo (self.playImageView.mas_right).with.offset(2);
        make.width.mas_offset(80);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-8);
        make.height.mas_offset(15);
    }];
    
    [_fromLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_numberLabel.mas_right).with.offset(20);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-8);
        make.height.mas_offset(15);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
    }];
    
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(130);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
        make.top.equalTo(self.titleLabel.mas_bottom).with.offset(10);
        make.height.mas_offset(15);
    }];
    
    
    [_picImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
        make.top.equalTo(self.contentView.mas_top).with.offset(10);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(0);
        make.width.mas_offset(85);
    }];
    
    [_cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo (_backImageVeiw.mas_top).with.offset(10);
        make.right.equalTo(self.contentView.mas_right).with.offset(-20);
        make.width.mas_offset(20);
        make.height.mas_offset(20);
    }];
        
}


- (void)setModel:(LoveListenModelFirstData *)model {
    
    _model = [[LoveListenModelFirstData alloc] init];
    _model = model;
    
    [_picImageView sd_setImageWithURL:[NSURL URLWithString:model.item_img] placeholderImage:PLACEHOLDERIMAGE];
    _titleLabel.text = model.item_name;
    _contentLabel.text = model.item_lastmusic;
    _numberLabel.text = [NSString stringWithFormat:@"%ld", model.item_views];
    _fromLabel.text = [NSString stringWithFormat:@"by %@", model.item_manager];
}

-(void)setModelArr:(NSMutableArray *)modelArr {
    _modelArr = [NSMutableArray array];
    _modelArr = modelArr;
}




@end
